<?php
/**
 * User: @lose
 * Date: 2019-10-10
 * Time: 18:00
 */

namespace Biz\model\store;

use Doraemon\pockets\datebase\BaseDbModel;

class StoreAccount extends BaseDbModel
{
    const _CONFIG_FILE_ = 'db_store';

    const _CONFIG_SELECT_ = 'db_store';

    const _DATABASE_ = 'store';

    const _TABLE_NAME = 'store_account';


    const BOARD_BRAND = 1;//进口品牌
    const NOT_BOARD_BRANFD = 0;//非进口品牌

    const BOARD_MAP = [
        self::NOT_BOARD_BRANFD => '不是',
        self::BOARD_BRAND => '是'
    ];
    const BRAND_TYPE = 1;//品牌方
    const AGENT_TYPE = 2;//代理方
    const SERVER_TYPE_MAP = [
         self::BRAND_TYPE =>"品牌方",
        self::AGENT_TYPE => '代理商'
    ];

    const CHECK_DEFAULT= 0 ;//未审核
    const CHECK_SUCC = 1; //审核成功
    const CHECK_FAIL= 2;//审核失败

    const AUTH_DEFAULT = 0;//未认证
    const AUTH_SUCC= 1;//认证成功
    const AUTH_FAIL= 2;//认证失败
    const AUTH_MAP = [
         4=> '全部',
         self::AUTH_DEFAULT =>'未付款',
         self::AUTH_SUCC => '认证成功',
         self::AUTH_FAIL => '认证失败'
    ];

    const TEST_ACCOUNT = 1;//测试账户
    const NOT_TEST_ACCOUNT = 0;//非测试

    const CATEGORY_MAP = ['瓷砖', '地板','洁具','淋浴房','门窗木门','整屋定制','设备机电','漆','其他品类'];

    const IS_PAID  = 1;//已付费
    const NOT_PAID = 0;//未付费

    public static function getListByWhere($where, $field = '*')
    {
        return self::select($field, $where);
    }

    public static function getListByAdmin($where, $limit)
    {
        return self::select('*', [
            'AND' => $where,
            'LIMIT' => $limit
        ]);
    }

    public static function add($data)
    {
        $result = self::insert($data)->rowCount();
        if($result) {
            return self::id();
        }

        return false;
    }

    public static function updateById($id, $data)
    {
        $result = self::update($data, ['id' => $id])->rowCount();
        if($result) {
            return $id;
        }

        return false;
    }

    public static function getInfo($id)
    {
        return self::get('*', ['id' => $id]);
    }

    public static function getCount($where)
    {
        return self::count($where);
    }


    public static function getInfoByWhere($where , $field = "*")
    {
        return self::get($field ,$where);
    }



}